import 'package:fixnum/fixnum.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:im_demo/app/data/chat/api/api.dart';
import 'package:im_demo/utils/logger_util.dart';

import '../../../data/chat/api/request/add_group_request.dart';
import '../../../data/chat/api/request/test_post_request.dart';

class HomeController extends GetxController {
  var editTextController = TextEditingController();

  @override
  void onInit() {
    super.onInit();

    editTextController.addListener(() {});
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void httpRequest() async {
    List<BigInt> users = [
      BigInt.from(2),
      BigInt.from(3),
      BigInt.from(4),
      BigInt.from(5),
    ];
    AddGroupRequest request = AddGroupRequest(
      'TestGroup16',
      'desc',
      BigInt.from(1),
      users,
    );
    logE('httpRequest()->request:${request.toJson()}');

    final result = await Api().addGroup(request);
    logE('httpRequest()->result:${result.isSuccess},${result.data}');

    final response = result.data!;
    logE(
      'httpRequest()->response:${response.code},${response.message},${response.message}',
    );
  }

  void testPost() async {
    final TestPostRequest request = TestPostRequest(
      'test post',
      'test post body',
      1,
    );

    logE('httpRequest()->testPost:${request.toJson()}');

    final result = await Api().testPost(request);
    logE('httpRequest()->result:${result.isSuccess},${result.data}');

    final response = result.data!;
    logE(
      'httpRequest()->response:${response.title},${response.body},${response.userId},${response.id}',
    );

    //   _dio.BaseOptions baseOptions = _dio.BaseOptions(
    //     headers: {
    //       // HttpHeaders.acceptHeader:"application/json",
    //       HttpHeaders.acceptHeader: _dio.Headers.jsonContentType,
    //     },
    //     contentType: _dio.Headers.jsonContentType,
    //     responseType: _dio.ResponseType.json,
    //   );
    //
    //   _dio.Dio dio = _dio.Dio(baseOptions);
    //   _dio.Response response = await dio.post(
    //     'https://jsonplaceholder.typicode.com/posts',
    //     data: request.toJson(),
    //   );
    //   logE('httpRequest()->response:${response.toString()}');
  }
}
